package com.neusoft.neu24.myproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyFactory {
    private SellTickets station  ;

    public void setStation(SellTickets station) {
        this.station = station;
    }

    public  SellTickets getProxyObject() {
        return     (SellTickets) Proxy.newProxyInstance(station.getClass().getClassLoader(),
                station.getClass().getInterfaces(),
                new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        System.out.println("代理对象执行方法前");
//                        调用目标对象的具体的方法
                        Object result = method.invoke(station, args);
                        System.out.println("代理对象执行方法后");
                        return result;
                    }
                });

    }
}
